package com.hmall.item.controller;


import com.hmall.item.constatnts.MqConstants;
import com.hmall.item.pojo.Item;
import com.hmall.item.pojo.PageDTO;
import com.hmall.item.service.ItemService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("item")
public class ItemConteroller {
    @Autowired
    ItemService itemService;



    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @GetMapping("list")
    public PageDTO<Item> getPageItem(@RequestParam("page") Integer page,@RequestParam("size")Integer size){
        return itemService.getPageItem(page,size);

    }

    //添加商品
    @PostMapping
    public void addItemShop(@RequestBody Item item){
        itemService.addItemShop(item);
    }

    //上架、或者下
    @PutMapping("/status/{id}/{status}")
    public void reviseItemStatus(@PathVariable Long id,@PathVariable("status")Integer status){
        itemService.reviseItemStatus(id,status);
    }

    /**
     * 修改商品
     */
    @PutMapping
    public void updateItemById(@RequestBody Item item){
        itemService.updateItemById(item);
    }

    /**
     * 删除商品
     */
    @DeleteMapping("{id}")
    public void deleteItemById(@PathVariable("id") Long id){
        itemService.deleteItemById(id);
    }

    /**
     * 根据id查找用户
     */
    @GetMapping("{id}")
    public Item selectItemById(@PathVariable("id") Long id){
        return itemService.selectItemById(id);
    }


    @PutMapping("/stock/{itemId}/{num}")
    public void reduceGoodsFrequency(@PathVariable("itemId") Long itemId,
                            @PathVariable("num") Integer num){
        itemService.reduceGoodsFrequency(itemId,num);

    }


    @PutMapping("/update/{id}/{stock}")
    void updateItem(@PathVariable("id") Long id, @PathVariable("stock") Integer stock){
        itemService.updateItem(id,stock);
    }

    @RequestMapping("/item/{itemId}/{num}")
    void updateStock(@PathVariable("itemId") Long id,@PathVariable("num") Integer num){
        itemService.updateStock(id,num);
    }


}
